#!/usr/bin/python
#coding:utf-8
__author__ = 'hsd'


import tornado.httpclient
import re
import pandas as pd
import sys
reload(sys)
sys.setdefaultencoding('utf8')
comment_utf8 = []
url='http://www.9game.cn/tpl/pc/common/commentajax.html?count=1000&total=10003&gameid=539038&platform_id=2&offset=20&isAjax=1'
http_header = {'User-Agent':'Chrome'}
http_request = tornado.httpclient.HTTPRequest(url=url,method='GET',headers=http_header)
http_client = tornado.httpclient.HTTPClient()
http_response = http_client.fetch(http_request)
body = http_response.body
commentId=re.compile('<li commentId=\"(.*)\">').findall(body)
comment_time=re.compile('<span class=\"time\">(.*)<\/span>').findall(body)
comment=re.compile('<p class=\"text\">(.*)<\/p>').findall(body)
for item in comment:
    item.decode('utf8')
comment_utf8.append(item)
result = pd.DataFrame([commentId,comment_time,comment]).T
print result
result.to_csv(r'short.csv')